import {
    getProductManualByPaid,
    getRepairForStaff,
    getMaintainctrlCustomrecordOne,
    getProductarchiveByaddressDetail,
    getProductArchiveRemoteCode,
    getOldInfoAlarmData,
    getPorductArchiveOne,
    preLoadPerdeviceParamValue,
    getAllProductarchiveByaddress,
    getProductarchiveAddress,
    getProductarchiveByparam
} from '@/api/server';
import { apiService } from '@/api/apiService';

export function deviceviewSetup () {
    // 通过uuid获取产品信息
    const getProductByPaid = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getProductManualByPaid,
                param: param,
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    // // 获取报修记录
    const getRepairRecord = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getRepairForStaff,
                param: param,
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    // 获取客户记录
    const getCustomerRecord = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getMaintainctrlCustomrecordOne,
                param: param,
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    // 获取我的设备/所有设备
    const getDevice = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getProductarchiveByaddressDetail,
                param: param,
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    // 获取远程码
    const getRemoteData = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getProductArchiveRemoteCode,
                param: param,
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    // 获取设备报警信息
    const getAlarmDataInfo = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getOldInfoAlarmData,
                param: param,
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    // 获取设备档案详情
    const getDeviceFileInfo = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getPorductArchiveOne,
                param: param,
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    // 获取指定uuid设备所有参数数据
    const getMachineParametersValue = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: preLoadPerdeviceParamValue,
                param: param,
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    // 获取全部客户
    const getAllCustomers = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getAllProductarchiveByaddress,
                param: param,
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    // 获取地区
    const getProductarchiveAddressArea = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getProductarchiveAddress,
                param: param,
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    // 不分页获取全部设备
    const getProductarchiveByparamNoPage = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getProductarchiveByparam,
                param: param,
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    return {
        getProductByPaid,
        getRepairRecord,
        getCustomerRecord,
        getDevice,
        getRemoteData,
        getAlarmDataInfo,
        getDeviceFileInfo,
        getMachineParametersValue,
        getAllCustomers,
        getProductarchiveAddressArea,
        getProductarchiveByparamNoPage
    };
}
